package dk.netl.dashboard.widgets.burndownwidget;

import javafx.scene.shape.Rectangle;
import javafx.scene.Group;
import javafx.scene.paint.Color;
import javafx.scene.image.ImageView;
import javafx.scene.image.Image;
import javafx.animation.Timeline;
import javafx.animation.KeyFrame;

public class BurndownWidget extends Group {

    public var x: Number;
    public var y: Number;
    public var width: Number;
    public var height: Number;
    def burndownIV: ImageView = ImageView {
                image: Image {
                    backgroundLoading: true
                    url: "http://spreadsheets.google.com/oimg?key=0Agj5nvEzS2zDdEktTTlfMGg3eElZTFZsbk9MSXhNMlE&oid=13&zx=sqizd8fq86hl"
                    width: 500
                    height: 300
                }
                opacity: 0.8
                translateY: 20
                translateX: 20
            }
    def velocityIV: ImageView = ImageView {
                image: Image {
                    backgroundLoading: true
                    url: "http://spreadsheets.google.com/oimg?key=0Agj5nvEzS2zDdE03U1NsX1k1OXJuMTd4a1hvQkdjZXc&oid=1&v=1272996236642"
                    width: 500
                    height: 300
                }
                opacity: 0.8
                translateY: 340
                translateX: 20
            }

    def update: Timeline = Timeline {
                repeatCount: Timeline.INDEFINITE
                keyFrames: [
                    KeyFrame {
                        time: 60m
                        action: function() {
                            burndownIV.image = Image {
                                        backgroundLoading: true
                                        url: "http://spreadsheets.google.com/oimg?key=0Agj5nvEzS2zDdEktTTlfMGg3eElZTFZsbk9MSXhNMlE&oid=13&zx=sqizd8fq86hl"
                                        width: 500
                                        height: 300
                                    }
                            velocityIV.image = Image {
                                        backgroundLoading: true
                                        url: "http://spreadsheets.google.com/oimg?key=0Agj5nvEzS2zDdE03U1NsX1k1OXJuMTd4a1hvQkdjZXc&oid=1&v=1272996236642"
                                        width: 500
                                        height: 300
                                    }
                        }
                    }
                ]
            };

    init {
        update.play();
        content = [
                    Rectangle {
                        arcHeight: 30
                        arcWidth: 30
                        opacity: 0.5
                        fill: Color.web("#005284",1.0)
                        x: bind x
                        y: bind y
                        width: bind width
                        height: bind height
                    },burndownIV
                    ,velocityIV
                ]
    }
}
